Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ReactAndroid to use the AGP NDK Apis #32443

Closed
wants to merge 1 commit into from

Conversation

cortinico
Copy link
Contributor

Summary:
This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the ndk-build command. This means that the native build will be now invoked
with the :ReactAndroid:externalNativeBuild<Variant> task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:

  • The native build will run on every build now. Given the complexity of our native build graph,
    even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
    targets and mention that there is no work to be done. I believe this could be impactful for local
    development experience. The mitigation I found was to apply an abiFilter to build only the ABI
    of the target device (e.g. arm64 for a real device and so on).
    This reduces the native build to ~10 seconds.
  • All the change to the react-native-gradle-plugin source will cause the Gradle tasks to be
    considered invalid. Therefore they will re-extract the header files inside the folders that are
    used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
    locally, if you plan to edit react-native-gradle-plugin and relaunch
    rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
    would be to invoke the tasks like
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Oct 20, 2021
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

@pull-bot
Copy link

pull-bot commented Oct 20, 2021

Messages
📖

📋 Missing Changelog - Can you add a Changelog? To do so, add a "## Changelog" section to your PR description. A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

📖 📋 Missing Test Plan - Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.
📖 📋 Missing Summary - Can you add a Summary? To do so, add a "## Summary" section to your PR description. This is a good place to explain the motivation for making this change.

Generated by 🚫 dangerJS against 5c57396

@analysis-bot
Copy link

analysis-bot commented Oct 20, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 3dff1fa
Branch: main

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 22, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: 83f963dda66f8c4356e05b6f19a98aa54a7ba995
@pull-bot
Copy link

PR build artifact for 4288392 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 25, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: ee8d31a14b779aed43a1ccb4b9b9a119af309574
@pull-bot
Copy link

PR build artifact for 1675356 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 25, 2021
Summary:
While working updating the codeden Makefile template for Android, I've removed
the `libreact_debug` and `libreact_render_debug` dependencies as they were unused in a
simple turbomodule. Turns out that `:ReactAndroid` is depending on having those dependencies.

Moving the build file to use AGP APIs, triggers this scenario and is making `ReactAndroid`
failing to build (see the build status for facebook#32443).

I'm updating the codegen Makefile template to reintrodce the two libraries + I've update the prebuilt
makefile (used in the playbook) to include `react_debug` prebuilts as they were missing.

Changelog:
[Internal] [Changed] - Re-add libreact_debug to codegen makefile and add prebuilts for them

Differential Revision: D31900675

fbshipit-source-id: 6ace1c2bd27c93773f587fa604f8a27e8c26b1f8
cortinico added a commit to cortinico/react-native that referenced this pull request Oct 25, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: 0736891c8197b424d3db30ea593d6bc61fd69ffd
@pull-bot
Copy link

PR build artifact for af60c49 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 26, 2021
Summary:
While working updating the codeden Makefile template for Android, I've removed
the `libreact_debug` and `libreact_render_debug` dependencies as they were unused in a
simple turbomodule. Turns out that `:ReactAndroid` is depending on having those dependencies.

Moving the build file to use AGP APIs, triggers this scenario and is making `ReactAndroid`
failing to build (see the build status for facebook#32443).

I'm updating the codegen Makefile template to reintrodce the two libraries + I've update the prebuilt
makefile (used in the playbook) to include `react_debug` prebuilts as they were missing.

Changelog:
[Internal] [Changed] - Re-add libreact_debug to codegen makefile and add prebuilts for them

Differential Revision: D31900675

fbshipit-source-id: cfdfe1293d45cdc2539c933fb2410cc64a444c4d
cortinico added a commit to cortinico/react-native that referenced this pull request Oct 26, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: 56b42d8127bce178697aefdb9da1ec467a622057
@pull-bot
Copy link

PR build artifact for b96a530 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 26, 2021
Summary:
While working updating the codeden Makefile template for Android, I've removed
the `libreact_debug` and `libreact_render_debug` dependencies as they were unused in a
simple turbomodule. Turns out that `:ReactAndroid` is depending on having those dependencies.

Moving the build file to use AGP APIs, triggers this scenario and is making `ReactAndroid`
failing to build (see the build status for facebook#32443).

I'm updating the codegen Makefile template to reintrodce the two libraries + I've update the prebuilt
makefile (used in the playbook) to include `react_debug` prebuilts as they were missing.

Changelog:
[Internal] [Changed] - Re-add libreact_debug to codegen makefile and add prebuilts for them

Differential Revision: D31900675

fbshipit-source-id: a52b1609bf85aa3ac9800669708fa07d091ac195
cortinico added a commit to cortinico/react-native that referenced this pull request Oct 26, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: adefc9b28ce6454c6cadaef9369d4965854a46de
@pull-bot
Copy link

PR build artifact for 315313f is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@analysis-bot
Copy link

analysis-bot commented Oct 26, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,350,538 +1,060,540
android hermes armeabi-v7a 8,332,539 +478,484
android hermes x86 9,982,921 +1,325,898
android hermes x86_64 9,768,125 +1,151,997
android jsc arm64-v8a 10,665,117 +873,751
android jsc armeabi-v7a 9,310,594 +558,371
android jsc x86 10,777,171 +1,036,935
android jsc x86_64 11,216,323 +875,261

Base commit: 3dff1fa
Branch: main

facebook-github-bot pushed a commit that referenced this pull request Oct 27, 2021
Summary:
While working updating the codeden Makefile template for Android, I've removed
the `libreact_debug` and `libreact_render_debug` dependencies as they were unused in a
simple turbomodule. Turns out that `:ReactAndroid` is depending on having those dependencies.

Moving the build file to use AGP APIs, triggers this scenario and is making `ReactAndroid`
failing to build (see the build status for #32443).

I'm updating the codegen Makefile template to reintrodce the two libraries + I've update the prebuilt
makefile (used in the playbook) to include `react_debug` prebuilts as they were missing.

Changelog:
[Internal] [Changed] - Re-add libreact_debug to codegen makefile and add prebuilts for them

Reviewed By: ShikaSD

Differential Revision: D31900675

fbshipit-source-id: ff188c0498a0dca4a951a548a580ca8dd0674782
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

cortinico added a commit to cortinico/react-native that referenced this pull request Oct 27, 2021
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: ff2415b4b1d835b2486458b75b5f5dff2340870a
Summary:
Pull Request resolved: facebook#32443

This diff removes all the custom Gradle machinery to build the native code and delegates to AGP
the triggering of the `ndk-build` command. This means that the native build will be now invoked
with the `:ReactAndroid:externalNativeBuild<Variant>` task.

An important thing to notice is that that task will always run, and will delegate to Make the
compilation avoidance. If you invoke the task twice, the second time it will be significantly faster.
On my machine this takes ~6/7 mins the first time, and 30 seconds the second time.

There are some gotchas that are worth noting:
* The native build will run on every build now. Given the complexity of our native build graph,
even with an up-to-date build, Make will still take ~30 seconds on my machine to analyse all the
targets and mention that there is no work to be done. I believe this could be impactful for local
development experience. The mitigation I found was to apply an `abiFilter` to build only the ABI
of the target device (e.g. arm64 for a real device and so on).
This reduces the native build to ~10 seconds.
* All the change to the `react-native-gradle-plugin` source will cause the Gradle tasks to be
considered invalid. Therefore they will re-extract the header files inside the folders that are
used by Make to compile, triggering a near-full rebuild. This can be a bit painful when building
 locally, if you plan to edit react-native-gradle-plugin and relaunch
 rn-tester (seems to be like an edge case scenario but worth pointing out). The mitigation here
 would be to invoke the tasks like

```
gw :packages:rn-tester:android:app:installHermesDebug -x prepareBoost -x prepareLibevent -x prepareGlog \
   -x prepareJSC -x extractNativeDependencies -x generateCodegenArtifactsFromSchema \
   -x generateCodegenSchemaFromJavaScript
```

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: ShikaSD

Differential Revision: D31683721

fbshipit-source-id: 2364fb678a04428f9c9280ddbd4ff6f15ecfbc84
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31683721

@pull-bot
Copy link

PR build artifact for 5c57396 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in b0711f1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants